"""
查询mds监控信息，返回ONEStor2的单mds请求数。

cluster_graphite_render_data返回：
[{'target': 'servers.ONEStor2.fs.mds.req', 'datapoints': [[3078.1, 1729583760], [3265.7, 1729583770], [3308.0, 1729583780], [3412.9, 1729583790], [3428.5, 1729583800], [3059.2, 1729583810], [2898.1, 1729583820], [3215.9, 1729583830], [3089.4, 1729583840], [3378.0, 1729583850], [3370.3, 1729583860], [3445.9, 1729583870], [3070.5, 1729583880], [2980.6, 1729583890], [3113.4, 1729583900], [2929.4, 1729583910], [2942.2, 1729583920], [2876.3, 1729583930], [2952.1, 1729583940], [2942.2, 1729583950], [3076.2, 1729583960], [3023.8, 1729583970], [2867.8, 1729583980], [2899.8, 1729583990], [2983.4, 1729584000], [3089.0, 1729584010], [3590.6, 1729584020], [3078.4, 1729584030], [3071.4, 1729584040], [2907.7, 1729584050], [2943.9, 1729584060]]}]

"""

import requests


def get_h3c_graphite_render_data():
    # 拼接成登陆url
    base_url = "http://地址"

    # 生成请求URL
    # cluster_graphite_render_1 = "/api/v3/onestor"
    cluster_graphite_render_2 = "/graphite/render"
    cluster_graphite_render_3 = "?format=json&from=-5minute&target=servers.ONEStor2.fs.mds.req"
    cluster_graphite_render_url = base_url + cluster_graphite_render_2 + cluster_graphite_render_3


    # 发送GET请求，得到返回数据
    cluster_graphite_render_res = requests.get(
        url=cluster_graphite_render_url,
        headers={
            'content-type': "application/json",
        })
    cluster_graphite_render_data = cluster_graphite_render_res.json()

    # print(cluster_graphite_render_data[0]['datapoints'])
    max_mds_req = 0
    for item in cluster_graphite_render_data[0]['datapoints']:
        if (item[0] > max_mds_req):
            max_mds_req = item[0]

    return max_mds_req


if __name__ == '__main__':
    max_mds_req = get_h3c_graphite_render_data()
    print(max_mds_req)
